/*
 * @Descripttion:
 * @Author: YuZhenJing
 * @Date: 2020-01-02 15:40:03
 * @LastEditors: YuZhenJing
 * @LastEditTime: 2020-05-08 15:15:53
 */
import store from '@/store'
import AsmClient from 'asm-client'

// 变化后的主题对象
let changeThemeObj = {}
// 变化主题函数
export function changeTheme() {
  let themeValue =
    AsmClient.Auth.themeObj.get() == null
      ? 'theme-default'
      : AsmClient.Auth.themeObj.get()
  if (themeValue == 'theme-default') {
    // 默认主题
    changeThemeObj = AsmClient.initParam.htmlParam.defaultTheme
  } else {
    // 藏阁主题
    const colorCF = '#7e57c2'
    changeThemeObj = {
      ...AsmClient.initParam.htmlParam.defaultTheme,
      ...{
        primary: colorCF,
        'lighten-primary': AsmClient.Colors.lighten(colorCF, -40),
        'dark-primary': AsmClient.Colors.lighten(colorCF, -40),
        secondary: '#4a148c',
        'lighten-secondary': AsmClient.Colors.lighten('#4a148c', -40)
      }
    }
  }
  store.commit('login/SET_THEME', changeThemeObj)
  AsmClient.Colors.setColors(changeThemeObj)
  // 根据运行模式区分主题加载项
  if (process.env.VUE_APP_SINGLERUN === 'true') {
    //独立运行模式
    window.asm = {
      theme: {
        themeObj: changeThemeObj
      }
    }
  } else {
    //微服务模式，此对象在asm-main定义
    window.asm.theme.themeObj = changeThemeObj
    window.asm.theme.changeTheme(themeValue)
  }
}

export default {
  ...changeThemeObj
}
